99B - Help Chef Gerasim - CodeForces Solution


implementation sortings *1300

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>



using namespace std;



#define pb push_back

#define eb emplace_back

#define f first

#define s second

#define deb(a) cerr << #a << " = " << a << "\n";

#define all(x) (x).begin(), (x).end()

#define file() { ifstream cin("input.txt"); ofstream cout("output.txt"); }

#define correct(x, y, n, m) (0 <= (x) && (x) < (n) && 0 <= (y) && (y) < (m))

#define y1 y1212312

#define int long long



typedef long long ll;

typedef long double ld;

typedef pair <int, int> pii;



const ll INF = 2e18;

const ll mod = 1e9 + 7;

const int inf = 1e9;

const ld EPS = 1e-12;

const ld Pi = acosl(-1);

const int P = 31;

const int dx[2] = {0, 1};

const int dy[2] = {1, 0};



int qqq = 1;



mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());



int n;



void solve() {

    cin >> n;

    vector <int> a(n);

    map <int, int> mp, ind;

    for (int i = 0; i < n; i++) {

        cin >> a[i];

        mp[a[i]]++;

        ind[a[i]] = i;

    }



    if (n == 2) {

        int delta = abs(a[1] - a[0]);

        if (delta % 2) {

            cout << "Unrecoverable configuration.\n";

            return;

        }

        if (delta == 0) {

            cout << "Exemplary pages.\n";

            return;

        }

        cout << delta / 2 << " ml. from cup #" << (a[1] > a[0] ? 1 : 2) << " to cup #" << (a[1] > a[0] ? 2 : 1) << ".\n";

        return;

    }



    sort(a.begin(), a.end());

    a.resize(unique(a.begin(), a.end()) - a.begin());



    if ((int)a.size() == 1) {

        cout << "Exemplary pages.\n";

        return;

    }





    if ((int)a.size() != 3) {

        cout << "Unrecoverable configuration.\n";

        return;

    }



    if (mp[a[0]] != 1 || mp[a[1]] != n - 2 || mp[a[2]] != 1) {

        cout << "Unrecoverable configuration.\n";

        return;

    }



    if (a[1] - a[0] != a[2] - a[1]) {

        cout << "Unrecoverable configuration.\n";

        return;

    }



    int delta = a[1] - a[0];

    cout << delta << " ml. from cup #" << ind[a[0]] + 1 << " to cup #" << ind[a[2]] + 1 << ".\n";

}



signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0); cout.tie(0);

    clock_t tStart = clock();

    //cin >> qqq;

    while (qqq--) {

        solve();

    }

    cerr << "Runtime is:" << (long double) (clock() - tStart) / CLOCKS_PER_SEC << '\n';

    return 0;

}


Comments

Submit
0 Comments
More Questions

279B - Books
1374B - Multiply by 2 divide by 6
1093B - Letters Rearranging
1213C - Book Reading
1468C - Berpizza
1546B - AquaMoon and Stolen String
1353C - Board Moves
902A - Visiting a Friend
299B - Ksusha the Squirrel
1647D - Madoka and the Best School in Russia
1208A - XORinacci
1539B - Love Song
22B - Bargaining Table
1490B - Balanced Remainders
264A - Escape from Stones
1506A - Strange Table
456A - Laptops
855B - Marvolo Gaunt's Ring
1454A - Special Permutation
1359A - Berland Poker
459A - Pashmak and Garden
1327B - Princesses and Princes
1450F - The Struggling Contestant
1399B - Gifts Fixing
1138A - Sushi for Two
982C - Cut 'em all
931A - Friends Meeting
1594A - Consecutive Sum Riddle
1466A - Bovine Dilemma
454A - Little Pony and Crystal Mine